package com.threaddemo4;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class ThenAcceptRunDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<String> f1 = CompletableFuture.supplyAsync(()->{
            System.out.println("F1 " + Thread.currentThread().getName());
            return "F1 返回值";
        });

        //thenAccpet:接收上一个任务的返回值 作为参数  本身不能返回数据
        CompletableFuture f2 = f1.thenAccept(r->{
            System.out.println("F2 " + Thread.currentThread().getName());
        });

        CompletableFuture f3 = f1.thenRun(()->{
            System.out.println("F3 " + Thread.currentThread().getName());
        });

        System.out.println("ret1 = " + f1.get());
        System.out.println("ret2 = " + f2.get());
        System.out.println("ret3 = " + f3.get());

    }
}
